<?php

namespace Home\Controller;

use Think\Controller;

/**
 * @Author: Martin Zhou
 * @Version: 1.0.1
 * @Copyright Tencent Security Response Center (TSRC)
 * @Project  https://security.tencent.com/index.php/xsrc
*/

class PostController extends PublicController{

    public function index($key="")
    {
	   if($key == ""){
            $model = M('post');  
        }else{
            $where['title'] = array('like',"%$key%");
            $where['name'] = array('like',"%$key%");
            $where['_logic'] = 'or';
            $model = M('post')->where($where); 
        } 
        
        $count  = $model->where($where)->count();
        $Post = new \Extend\Page($count,15);
        $show = $Post->show();
        $pages = $model->limit($Post->firstRow.','.$Post->listRows)->where($where)->where('visible=1')->order('id DESC')->select();
        $this->assign('model', $pages);
        $this->assign('page',$show);
        $this->display();     
    }


    public function view(){
		$id = I('get.id',0,'int');
        $model = M('post')->where('id='.$id)->where('visible=1')->find();
        $this->assign('model',$model);
        $this->display();
    }
}
